# 大恒雷电预测数据可视化类测试类
import unittest
from apps.dhlp.data_vis import DataVis

class TDataVis(unittest.TestCase):
    # python -m unittest -v uts.apps.dhlp.t_data_vis.TDataVis.test_get_rec_db
    def test_get_rec_db(self):
        csv_fn = 'work/datas/v0/time_periods.csv'
        rec_db = DataVis.get_rec_db(csv_fn=csv_fn) # 获取闪电数据主表条目

    # python -m unittest -v uts.apps.dhlp.t_data_vis.TDataVis.test_get_devs_recs
    def test_get_devs_recs(self):
        csv_fn = 'work/datas/v0/time_periods.csv'
        dev_recs = DataVis.get_devs_recs(csv_fn=csv_fn)
        # 每个设备按照条目数进行排序
        dids = sorted(dev_recs.keys(), key=lambda dev_id: len(dev_recs[dev_id]["tls"]) + len(dev_recs[dev_id]["norms"]), reverse=True)
        print(f'dids: {type(dids)};')
        for did in dids:
            print(f'### {did}: {len(dev_recs[did]["tls"]) + len(dev_recs[did]["norms"])};')
        '''
        ### F56AC57A1181CD: 380;
        ### F56AC4471179C5: 343;
        ### F56AC58103C5DD: 294;
        ### F56AC5301156A0: 284;
        ### F56AC3B40FF72A: 245;
        ### F56AC57910FA46: 239;
        '''

    # python -m unittest -v uts.apps.dhlp.t_data_vis.TDataVis.test_get_raw_datas
    def test_get_raw_datas(self):
        electric_fn = 'work/datas/v0/electric.txt'
        raw_datas = DataVis.get_raw_datas(electric_fn=electric_fn)

    # python -m unittest -v uts.apps.dhlp.t_data_vis.TDataVis.test_process_rec_raw_data
    def test_process_rec_raw_data(self):
        electric_fn = 'work/datas/v0/electric.txt'
        raw_datas = DataVis.get_raw_datas(electric_fn=electric_fn)
        rec_id = '4060' # ### 4060, 4061,4062
        X, y = DataVis.process_rec_raw_data(raw_datas=raw_datas, rec_id=rec_id)
        print(f'X: {X.shape}; y: {y.shape};')

    # python -m unittest -v uts.apps.dhlp.t_data_vis.TDataVis.test_umap_analysis
    def test_umap_analysis(self):
        DataVis.umap_analysis()
